/*
 * HapMatrix.h
 *
 *  Created on: Jan 20, 2012
 *      Author: pickrell
 */

#ifndef HAPMATRIX_H_
#define HAPMATRIX_H_

#include <string>
#include <vector>
#include <map>
#include <set>
#include "gzstream.h"
#include <sys/stat.h>
#include <sstream>
#include <stdlib.h>
#include <algorithm>
#include <cmath>
using namespace std;

class HapMatrix{
public:
	HapMatrix(string, string, string);
	HapMatrix(string, string, set<string>);
	void read_fastphase(string);
	void read_fastphase(string, set<string>);
	void read_snpfile(string);
	void read_genmap(string);
	void read_indfile(string);
	void print();
	vector<vector<bool> > H;
	map<int, string> index2ind;
	map<string, pair<int, int> > ind2index;
	map<string, string> ind2pop;
	map<int, string> index2snp;
	map<string, int> snp2index;
	map<string, bool> ind2found;
	vector<double> genmap;
	map<string, vector<string> > snp2info;
	int nhap;
	int nsnp;
	int K;
	vector<bool> snpinclude;
	vector<double> snpweight;
	vector<double> snpfreq;
	vector<float> f_mix;
	vector<float> f_source;
	vector<float> hzy_mix;
	vector<float> hzy_source;
	int set_weights(set<string>, set<string>, set<string>, float *, float *, float*, float*, float*);
	float calc_d(set<string>, int, int);
	void print_all_d(set<string>, double);
	set<string> allpops;
	map<string, map< string, vector<int> > > get_pairwise_counts(set<string>);
	map<string, map< string, vector<int> > > get_pairwise_counts(set<string>, set<pair<string, string> >);
	map<string, map<string, map<string, vector<int> > > >  gt_pairs(set<string>, set<pair<string, string> >);
	map<string, pair<int, int> > gt_snp(string, string, bool, bool);

	vector<pair<vector<float>, vector<float> > > bin_d(set<string>, double, double, double);
	vector<vector<float> > bin_d_lowmem(set<string>, double, double, double);
	vector<vector<float> > bin_d_freq_cor_lowmem(set<string>, vector<pair<float, float> >, double, double, double);
	vector<vector<float> > bin_d_freq_lowmem(set<string>, double, double, double);

};

#endif /* HAPMATRIX_H_ */
